/* define object with flexible ads */
var flexAdSpaceList = Object();
flexAdSpaceList["de-DE"] = Object();
flexAdSpaceList["en-GB"] = Object();

/* flexible ads for both language versions */
flexAdSpaceList["de-DE"]["sidebarRectangle"] = '<iframe src="http://rcm-eu.amazon-adsystem.com/'
											+ 'e/cm?t=kammerathnet-21&o=3&p=12&l=ur1&category='
											+ 'electronics&banner=1WY69X54P3YBP8EGFYR2&f=ifr" '
											+ 'width="300" height="250" scrolling="no" border="0" '
											+ 'marginwidth="0" style="border:none;" frameborder="0">'
											+ '</iframe>';
flexAdSpaceList["en-GB"]["sidebarRectangle"] = '<iframe src="http://rcm-eu.amazon-adsystem.com/e/cm?'
											+ 't=kamnetuk-21&o=2&p=12&l=ur1&category=ce&banner='
											+ '1V0FQHHJGZT8ANFJ30R2&f=ifr" width="300" height="250" '
											+ 'scrolling="no" border="0" marginwidth="0" '
											+ 'style="border:none;" frameborder="0"></iframe>';

/* dynamic responsive advertising script */
$(document).ready(function(){
	// configure the sky scraper after load
	configureSkyScraper();
});

$(window).resize(function(){
	// resize will also occure when devices
	// are changed into landscape or the 
	// browser on the desktop is scaled
	configureSkyScraper();
});

/* dynamic advertising implementation for the skyscraper:
	If there is sufficient space on the left, then the 
	skyscraper will go there fixed. If not, but the sidebar
	is visible (e.g. on tablets) then the skyscraper will go
	into the sidebar with its own box. If its on mobile devices
	such as android smartphones or the iphone, then the skyscraper
	will be replaced with a responsive ad
 */
function configureSkyScraper(){
	/* check if there is enough space for the skyscraper to 
		be fixed on the left side of the free space */
	var availableHeightBottom = ($(window).height()-$(".top").height());
	var availableWidthLeft = ($(window).width()-$(".content").width())/2;
	if(availableHeightBottom>610&&availableWidthLeft>185){
		/* position the skyscraper */
		$("#flexskyscraper").css("position","fixed");
		$("#flexskyscraper").css("box-shadow","2px 2px 5px 0px #cccccc");
		$("#flexskyscraper").css("top",60);
		$("#flexskyscraper").css("left",(availableWidthLeft-180));
		$("#flexskyscraper").show();
		$("#skyscrapersidebarbox").hide();

		/* insert code and request both skyscraper
			banner ads on the left and on the right */
		requestSkyscraper();
	}else{
		/* if not, then check if the sidebar is fixed 
			so it can be located in there with its own 
			sidebar box */
		if($(".sidebar:visible").length>0
			&&$(".contentbody:visible").length>0){
			/* there is space in the sidebar, but in order 
				to calculate the position and width we first 
				need to show it*/
			$("#skyscrapersidebarbox").show();

			/* calculate the left pos using the pos
				of the sidebar box content and its width
				so that the skyscraper aligns in the 
				center of it */
			var skyscraperLeftPos = parseInt($("#sidebarskyscraper").position().left)
									+ parseInt((($("#sidebarskyscraper").width()-160)/2));

			/* show the skyscraper in the side bar */
			$("#skyscrapersidebarbox").css("height","650px");
			$("#sidebarskyscraper").html("");
			$("#flexskyscraper").css("box-shadow","none");
			$("#flexskyscraper").css("position","absolute");
			$("#flexskyscraper").css("top",$("#sidebarskyscraper").position().top+10);
			$("#flexskyscraper").css("left",skyscraperLeftPos+"px");
			$("#flexskyscraper").show();

			/* inser code and request the skyscraper */
			requestSkyscraper();
		}else{
			/* disable the skyscraper on smartphones
			 and tablets in portrait mode */
			$("#flexskyscraper, #rightskyscraper").hide();

			/* enable alternative rectangle for the sidebar 
				on smartphones and tablets in portrait mode */
			$("#skyscrapersidebarbox").show();
			$("#skyscrapersidebarbox").css("height","auto");

			/* load the ad if its not yet there */
			if($("#sidebarskyscraper").html().length==0){
				$("#sidebarskyscraper").html(flexAdSpaceList
							[languageCode]["sidebarRectangle"]);
			}
		}
	}
}

/* adds the code to the div container 
	which then requests or loads the 
	skyscraper from google */
function requestSkyscraper(){
	/* make sure it is not already loaded */
	if($("#flexskyscraper").html().length==0){
		/* add the skyscraper code to the container */
		$("#flexskyscraper").html("<ins class=\"adsbygoogle\" "
			+"style=\"display:inline-block;width:160px;height:600px\" "
			+"data-ad-client=\"ca-pub-1779872529656954\" "
			+"data-ad-slot=\"9175115446\"></ins>");
     	
     	/* execute the google code loader for it */
     	(adsbygoogle = window.adsbygoogle || []).push({});
	}
}